package com.me.jingdongshop.ui.activity;

import android.content.Intent;
import android.os.Message;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.me.common.base.BaseActivity;
import com.me.jingdongshop.R;

/**
 * Created by ldl on 2017/5/7.
 * 送货时间界面
 */

public class DeliveryModeActivity extends BaseActivity {
    private TextView tvDeliveryTimeBack;   // 送货时间界面返回
    private TextView tvDeliveryWorkandtwo;          // 工作日、双休日
    private TextView tvDeliveryTwoandfestival;           // 双休、节假日
    private TextView tvDeliveryWork;       // 工作日
    private ImageView ivtvDeliveryWorkandtwoCheck;   // 工作日、双休日勾选
    private ImageView ivDeliveryTwoandfestivalCheck;   // 双休、节假日勾选
    private ImageView ivDeliveryWorkCheck;   // 工作日勾选
    private TextView tvDeliveryConfirm;        // 确定

    public static final int RESULT_CODE = 03;
    public static final int WORK_TWO = 0;
    public static final int TWO_FESTIVAL = 1;
    public static final int WORK = 2;
    private int currentCheckMode = WORK_TWO;

    @Override
    public int getLayoutRes() {
        return R.layout.activity_shopcart_delivery_mode;
    }

    @Override
    public void initView() {
        tvDeliveryTimeBack = (TextView) findViewById(R.id.tv_delivery_time_back);
        tvDeliveryWorkandtwo = (TextView) findViewById(R.id.tv_delivery_workandtwo);
        tvDeliveryTwoandfestival = (TextView) findViewById(R.id.tv_delivery_twoandfestival);
        tvDeliveryWork = (TextView) findViewById(R.id.tv_delivery_work);
        ivtvDeliveryWorkandtwoCheck = (ImageView) findViewById(R.id.iv_delivery_workandtwo_check);
        ivDeliveryTwoandfestivalCheck = (ImageView) findViewById(R.id.iv_delivery_twoandfestival_check);
        ivDeliveryWorkCheck = (ImageView) findViewById(R.id.iv_delivery_work_check);
        tvDeliveryConfirm = (TextView) findViewById(R.id.tv_delivery_confirm);
    }

    @Override
    public void initListener() {
        tvDeliveryTimeBack.setOnClickListener(this);
        tvDeliveryWorkandtwo.setOnClickListener(this);
        tvDeliveryTwoandfestival.setOnClickListener(this);
        tvDeliveryWork.setOnClickListener(this);
        ivtvDeliveryWorkandtwoCheck.setOnClickListener(this);
        ivDeliveryTwoandfestivalCheck.setOnClickListener(this);
        ivDeliveryWorkCheck.setOnClickListener(this);
        tvDeliveryConfirm.setOnClickListener(this);
    }

    @Override
    public void initData() {

    }

    @Override
    public void onClick(View v, int id) {
        switch (id) {
            case R.id.tv_delivery_time_back:
                finish();
                break;
            case R.id.tv_delivery_workandtwo:
            case R.id.iv_delivery_workandtwo_check:
                if (WORK_TWO != currentCheckMode) {
                    currentCheckMode = WORK_TWO;
                    ivtvDeliveryWorkandtwoCheck.setBackgroundResource(R.drawable.ischeck);
                    ivDeliveryTwoandfestivalCheck.setBackgroundResource(R.drawable.white_pink_circle);
                    ivDeliveryWorkCheck.setBackgroundResource(R.drawable.white_pink_circle);
                    return;
                }
                break;
            case R.id.tv_delivery_twoandfestival:
            case R.id.iv_delivery_twoandfestival_check:
                if (TWO_FESTIVAL != currentCheckMode) {
                    currentCheckMode = TWO_FESTIVAL;
                    ivtvDeliveryWorkandtwoCheck.setBackgroundResource(R.drawable.white_pink_circle);
                    ivDeliveryTwoandfestivalCheck.setBackgroundResource(R.drawable.ischeck);
                    ivDeliveryWorkCheck.setBackgroundResource(R.drawable.white_pink_circle);
                    return;
                }
                break;
            case R.id.tv_delivery_work:
            case R.id.iv_delivery_work_check:
                if (WORK != currentCheckMode) {
                    currentCheckMode = WORK;
                    ivtvDeliveryWorkandtwoCheck.setBackgroundResource(R.drawable.white_pink_circle);
                    ivDeliveryTwoandfestivalCheck.setBackgroundResource(R.drawable.white_pink_circle);
                    ivDeliveryWorkCheck.setBackgroundResource(R.drawable.ischeck);
                    return;
                }
                break;
            case R.id.tv_delivery_confirm:
                Intent intent = new Intent();
                String result = "";
                if (currentCheckMode == WORK_TWO) {
                    result = "工作日、双休日均可";
                } else if (currentCheckMode == TWO_FESTIVAL) {
                    result = "只双休、节假日送货";
                } else {
                    result = "只工作日送货";
                }
                intent.putExtra("deliveryMode", result);
                setResult(RESULT_CODE, intent);
                finish();
                break;
        }
    }

    @Override
    public void onHttpSuccess(int reqType, Message msg) {

    }

    @Override
    public void onHttpError(int reqType, String error) {

    }
}
